"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
// 访问器装饰器
// 一、基础语法
function demo0527(target, propertyKey, descriptor) {
    // target：对于静态访问来说值是【所属类】，对于实例访问器来说来说值是【所属类的原型对象】
    console.log(target);
    // propertyKey:方法的名称
    console.log(propertyKey);
    // descriptor：方法的描述对象
    console.log(descriptor);
}
class person0527 {
    get address() {
        return '北京石景山';
    }
    static get country() {
        return '中国';
    }
}
__decorate([
    demo0527
], person0527.prototype, "address", null);
__decorate([
    demo0527
], person0527, "country", null);
// 二、应用举例
// 需求：对Weather类的temp属性的set访问器进行限制，设置的最低温度为-50，最高温度为50
function RangeValidate(min, max) {
    return function (target, propertyKey, descriptor) {
        // 保存原始setter方法
        const original = descriptor.set;
        // 重写setter方法
        descriptor.set = function (value) {
            if (value < min || value > max) {
                throw new Error(`${propertyKey}的值应该在，${min}到${max}之间`);
            }
            if (original) {
                original.call(this, value);
            }
        };
    };
}
class Weather {
    constructor(_temp) {
        this._temp = _temp;
    }
    set temp(value) {
        this._temp = value;
    }
    get temp() {
        console.log('@夜南漫剪');
        return this._temp;
    }
}
__decorate([
    RangeValidate(-50, 50)
], Weather.prototype, "temp", null);
const weather = new Weather(20);
// 这里不能写_temp,因为是私有的
weather.temp = 20;
console.log(weather.temp);
